# Wed May 11 14:11:02 2022 edit
# 字符编码：UTF-8
# R 版本：R 4.2.0 x64 for window 11
# cgh163email@163.com
# 个人笔记不负责任，拎了个梨🍐🍈
#.rs.restartR()
require()
rm(list = ls());gc()
# https://www.shanghai-map.org.cn/tdt-hsjc/service/get.fun.php?action=getTownHospital&town=%E4%BA%94%E9%87%8C%E6%A1%A5%E8%A1%97%E9%81%93
require(jsonlite)
require(rlist)

url1 <- 'https://www.shanghai-map.org.cn/tdt-hsjc/service/get.fun.php?action=getTownHospital&town='
city <- readRDS('data_all/city.rds')

#单个下载调试 Wed May 11 14:28:34 2022 ------------------------------

k <- 3
paste0(url1,city[k,2])
download.file(url =   paste0(url1,city[k,2]),
              mode = 'wb',
              destfile = paste("data_all/2022年5月11日/",city[k,2], format(Sys.time(), "%Y%m%d%H%M%S"),round(proc.time()[3] * 100), sep = "_",'.json')
);kittyR::meowR(sound = 4)

js.dt <- list.load('data_all/2022年5月11日/_新成路街道_20220511142449_943054_.json')

js.dt[[2]] |> as.matrix() |> View()

#单个ok Wed May 11 14:27:39 2022 ---

#多个测试 Wed May 11 14:28:04 2022 ------------------------------
.rs.restartR() 重启r
require(rlist)

url1 <- 'https://www.shanghai-map.org.cn/tdt-hsjc/service/get.fun.php?action=getTownHospital&town='
city <- readRDS('data_all/city.rds')

# Wed May 11 14:29:50 2022 ---

down_json <- function(k = 1) {
  kittyR::meowR(sound = 5)#猫叫🐱
  cat('共',nrow(city),'第:',k,'🍐',city[k,2])
  Sys.sleep(runif(1,0.5,5)) # 随机时长CPU睡眠
  # Wed May 11 16:20:11 2022 ---
  list.load(paste0(url1, city[k, 2])) |>
    write_json(path = paste(
      "data_all/2022年5月11日/",
      k,
      city[k, 2],
      format(Sys.time(), "%Y%m%d%H%M%S"),
      round(proc.time()[3] * 100),
      sep = "_",
      '.json'
    )
   )

}

down_json(5)

#批量下载 Wed May 11 16:09:25 2022 ------------------------------

v <- c("Hello","while loop")
cnt <- 2

while (cnt < 7) {
  print(v)
  cnt = cnt + 1
}
# Wed May 11 17:06:33 2022 ---

k <- 11
while (k < 68) {
  kittyR::meowR(sound = 5)#猫叫🐱
  cat('共', nrow(city), '第:', k, '🍐', city[k, 2],'\n')
  Sys.sleep(runif(1, 3, 7)) # 随机时长CPU睡眠
  down_json(k = k)
  k <- k + 1
};kittyR::meowR(sound = 4)
#end Wed May 11 17:27:13 2022 ---

